package cn.ffcs.uec.outStaff.action;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zul.Messagebox;

import cn.ffcs.raptornuke.plugin.common.zk.ctrl.BasePortletComposer;
import cn.ffcs.raptornuke.plugin.common.zk.util.ZkUtil;
import cn.ffcs.uec.common.util.NodeVoUtil;
import cn.ffcs.uec.common.util.UecConstants;
import cn.ffcs.uec.organization.manager.UecOrgDeptManager;
import cn.ffcs.uec.organization.manager.UecOrgOrgsManager;
import cn.ffcs.uec.organization.model.UecOrgDept;
import cn.ffcs.uec.organization.vo.OrganizationRelationVo;
import cn.ffcs.uec.outStaff.action.bean.UecOutStaffPsnjobEditBean;
import cn.ffcs.uec.outStaff.model.UecOutStaffInfo;
import cn.ffcs.uec.post.dao.UecPostDao;
import cn.ffcs.uec.post.manager.UecPostManager;
import cn.ffcs.uec.post.model.UecPost;
import cn.ffcs.uec.post.vo.BasePostVo;
import cn.ffcs.uec.staff.model.UecPsnjob;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.DateUtil;
import cn.ffcs.uom.common.util.ListboxUtils;
import cn.ffcs.uom.common.util.PlatformUtil;
import cn.ffcs.uom.common.util.PubUtil;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.NodeVo;

@Controller
@Scope("prototype")
public class UecOutStaffPsnjobEditComposer extends BasePortletComposer {

	private static final long serialVersionUID = 3086340593438520480L;
	/**
	 * 页面bean
	 */
	private UecOutStaffPsnjobEditBean bean = new UecOutStaffPsnjobEditBean();
	/**
	 * 操作类型
	 */
	private String opType;
	/**
	 * 人员信息
	 */
	private UecOutStaffInfo qryUecOutStaffInfo;
	private UecOutStaffInfo uecOutStaffInfo;
	/**
	 * 任职信息
	 */
	private UecPsnjob qryUecPsnjob;
	/**
	 * 临时任职信息对象
	 */
	private UecPsnjob temporaryUecPsnjob = new UecPsnjob();
	/**
	 * 岗位
	 */
	private UecPost uecPost;
	/**
	 * 组织
	 */
	private UecOrgDept findUecOrgDept;

	/**
	 * 选择的组织
	 */
	private OrganizationRelationVo organization;
	/**
	 * 选择的基准岗位 三级
	 */
	private BasePostVo basePostVo;
	/**
	 * 二级基准岗
	 */
	private BasePostVo basePostVoB;
	/**
	 * 一级基准岗
	 */
	private BasePostVo basePostVoA;
	/**
	 * 外包人员基本信息更新标志
	 */
	private boolean outStaffInfoUpdateFlag = false;

	private UecPostDao uecPostDao = (UecPostDao) ApplicationContextUtil
			.getBean("uecPostDao");

	private UecOrgOrgsManager uecOrgOrgsManager = (UecOrgOrgsManager) ApplicationContextUtil
			.getBean("uecOrgOrgsManager");

	private UecOrgDeptManager uecOrgDeptManager = (UecOrgDeptManager) ApplicationContextUtil
			.getBean("uecOrgDeptManager");

	private UecPostManager uecPostManager = (UecPostManager) ApplicationContextUtil
			.getBean("uecPostManager");

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		Components.wireVariables(comp, bean);

		this.bean.getUecPostBandboxExt().addForward("onUecPostEditSelected",
				comp, "onUecPostEditSelectedResponse");
		this.bean.getOutStaffPkDept().addForward("onGetOrganization", comp,
				"onGetOrganizationResponse");
		this.bean.getOutStaffBasePost().addForward("onGetBasePost", comp,
				"onGetBasePostResponse");
	}

	/**
	 * 初始化窗口
	 * 
	 * @throws Exception
	 */
	public void onCreate$uecOutStaffPsnjobEditWindow() throws Exception {
		this.bindCombobox();
		this.bindBean();
	}

	/**
	 * 监听--领导职务
	 */
	/*public void onSelect$jobglbdef25() {
		String pkPsdoc = (String) bean.getJobglbdef25().getSelectedItem()
				.getValue();
		
		 // 如果领导职务为：部门第一负责人或者部门其他负责人，负责部门取部门
		 
		if ("1001AA100000001ZIHCY".equals(pkPsdoc)
				|| "1001AA100000001ZIHCZ".equals(pkPsdoc)) {
			if (null != findUecOrgDept) {
				bean.getDutyDeptName().setValue(findUecOrgDept.getName());
			} else if (null != qryUecPsnjob) {
				bean.getDutyDeptName().setValue(
						uecOrgDeptManager
								.getUecOrgDeptNameByPkDept(qryUecPsnjob
										.getJobglbdef26()));
			}
		} else {
			bean.getDutyDeptName().setValue(null);
		}
	}*/

	/**
	 * 监听组织树插件抛出的事件
	 * 
	 * @param event
	 */
	public void onGetOrganizationResponse(final ForwardEvent event) {
		if (event.getOrigin().getData() != null) {
			organization = (OrganizationRelationVo) event.getOrigin().getData();
			if ("ORG".equals(organization.getOrgType())) {
				ZkUtil.showError("调配后部门选项请选择到部门!", "错误提示");
				bean.getOutStaffPkDept().setValue(null);
				return;
			} else {
				// 根据部门主键：pkorg，找到该部门所在的公司
				findUecOrgDept = new UecOrgDept();
				findUecOrgDept.setPkDept(organization.getOrg());
				findUecOrgDept = uecOrgDeptManager
						.findUecOrgDeptByOrgDept(findUecOrgDept);
				if (null != findUecOrgDept) {
					//
					bean.getOrgName().setValue(
							uecOrgOrgsManager
									.getUecOrgOrgsNameByPkOrg(findUecOrgDept
											.getPkOrg()));
					bean.getUecPostBandboxExt().setValue(null);
					Events.postEvent("onUecDeptSelect", this.self,
							findUecOrgDept);
				}
			}
		}
	}

	/**
	 * 监听基准岗位参考树
	 * 
	 * @param event
	 */
	public void onGetBasePostResponse(final ForwardEvent event) {
		if (event.getOrigin().getData() != null) {
			basePostVo = (BasePostVo) event.getOrigin().getData();
			if (!"3".equals(basePostVo.getLv())) {
				ZkUtil.showError("基准岗位请选择到最后一级!", "错误提示");
				bean.getOutStaffBasePost().setValue(null);
				return;
			}
			// 根据所选择的的第三级基准岗位，查出第二级、第一级基准岗位，并赋值
			// 获取第三级基准岗位编码
			// String codeC = basePostVo.getCode();
			// 获取第三级基准岗位的上级编码
			String preCodeC = basePostVo.getPcode();
			// 根据三级基准岗位获取二级基准岗位
			basePostVoB = uecPostDao.getPreviousBasePostByCode(preCodeC);
			if (basePostVoB != null) {
				bean.getBasePostB().setValue(basePostVoB.getPostname());
				basePostVoA = uecPostDao.getPreviousBasePostByCode(basePostVoB
						.getPcode());
				if (basePostVoA != null) {
					bean.getBasePostA().setValue(basePostVoA.getPostname());
				}
			}
		}
	}

	/**
	 * 监听UecOrgPostBandboxExt传出的事件
	 * 
	 * @param event
	 */
	public void onUecPostEditSelectedResponse(final ForwardEvent event) {
		if (event.getOrigin().getData() != null) {
			uecPost = (UecPost) event.getOrigin().getData();
		}
	}

	/**
	 * bindBean
	 * 
	 * @throws Exception
	 */
	public void bindBean() throws Exception {
		opType = (String) arg.get("opType");
		if ("add".equals(opType)) {
			qryUecOutStaffInfo = (UecOutStaffInfo) arg.get("uecOutStaffInfo");
			bean.getPsnCode().setValue(qryUecOutStaffInfo.getPsnCode());
			bean.getPsnName().setValue(qryUecOutStaffInfo.getPsnName());
			this.bean.getUecOutStaffPsnjobEditWindow().setTitle("新增任职信息");
			bean.getUecOutStaffPsnjobEditDiv().setHeight("30%");
		}
		if ("view".equals(opType)) {
			qryUecPsnjob = (UecPsnjob) arg.get("uecPsnjob");
			qryUecOutStaffInfo = (UecOutStaffInfo) arg.get("uecOutStaffInfo");
			this.bean.getUecOutStaffPsnjobEditWindow().setTitle("查看任职信息");
			if (null != qryUecPsnjob) {
				bean.getPsnCode().setValue(qryUecOutStaffInfo.getPsnCode());
				bean.getPsnName().setValue(qryUecOutStaffInfo.getPsnName());
				PubUtil.fillBeanFromPo(qryUecPsnjob, bean);
				stringTransToDate();
				// 组织
				bean.getOrgName().setValue(
						uecOrgOrgsManager.getUecOrgOrgsNameByPkOrg(qryUecPsnjob
								.getPkOrg()));
				// 部门
				bean.getOutStaffPkDept().setValue(
						uecOrgDeptManager
								.getUecOrgDeptNameByPkDept(qryUecPsnjob
										.getPkDept()));
				// 岗位
				bean.getUecPostBandboxExt().setValue(
						uecPostManager.getUecPostNameByPkPost(qryUecPsnjob
								.getPkPost()));
				// 一级基准岗位
				bean.getBasePostA().setValue(
						uecPostManager.getUecPostNameByPkPost(qryUecPsnjob
								.getJobglbdef22()));
				// 二级基准岗位
				bean.getBasePostB().setValue(
						uecPostManager.getUecPostNameByPkPost(qryUecPsnjob
								.getJobglbdef23()));
				// 三级基准岗位
				bean.getOutStaffBasePost().setValue(
						uecPostManager.getUecPostNameByPkPost(qryUecPsnjob
								.getJobglbdef24()));
				// 负责部门
				bean.getDutyDeptName().setValue(
						uecOrgDeptManager
								.getUecOrgDeptNameByPkDept(qryUecPsnjob
										.getJobglbdef26()));
				bean.getButtonDiv().setVisible(false);
				PubUtil.disableComponent(bean.getUecOutStaffPsnjobEditWindow(),
						true);
			}
		}
		if ("edit".equals(opType)) {
			qryUecPsnjob = (UecPsnjob) arg.get("uecPsnjob");
			qryUecOutStaffInfo = (UecOutStaffInfo) arg.get("uecOutStaffInfo");
			this.bean.getUecOutStaffPsnjobEditWindow().setTitle("编辑任职信息");
			bean.getUecOutStaffPsnjobEditDiv().setHeight("30%");
			if (null != qryUecPsnjob) {
				// 存入临时对象
				temporaryUecPsnjob = qryUecPsnjob;
				PubUtil.fillBeanFromPo(qryUecPsnjob, bean);
				bean.getPsnCode().setValue(qryUecOutStaffInfo.getPsnCode());
				bean.getPsnName().setValue(qryUecOutStaffInfo.getPsnName());
				stringTransToDate();
				// 组织
				bean.getOrgName().setValue(
						uecOrgOrgsManager.getUecOrgOrgsNameByPkOrg(qryUecPsnjob
								.getPkOrg()));
				// 部门
				bean.getOutStaffPkDept().setValue(
						uecOrgDeptManager
								.getUecOrgDeptNameByPkDept(qryUecPsnjob
										.getPkDept()));
				// 岗位
				bean.getUecPostBandboxExt().setValue(
						uecPostManager.getUecPostNameByPkPost(qryUecPsnjob
								.getPkPost()));
				// 一级基准岗位
				bean.getBasePostA().setValue(
						qryUecPsnjob.getJobglbdef22Name());
				// 二级基准岗位
				bean.getBasePostB().setValue(
						qryUecPsnjob.getJobglbdef23Name());
				// 三级基准岗位
				bean.getOutStaffBasePost().setValue(
								qryUecPsnjob.getJobglbdef24Name());
				//人员类别（新）
				bean.getUecPsncl().setValue(qryUecPsnjob.getPkPsnclName());
				//岗位等级
				bean.getPostGrade().setValue(qryUecPsnjob.getJobglbdef3Name());
				//岗位层级
				bean.getNewPostLevel().setValue(qryUecPsnjob.getJobglbdef2Name());
				// 负责部门
			/*	bean.getDutyDeptName().setValue(
						uecOrgDeptManager
								.getUecOrgDeptNameByPkDept(qryUecPsnjob
										.getJobglbdef26()));*/
			}
		}
	}

	/**
	 * 保存
	 * 
	 * @throws Exception
	 */
	public void onOk() throws Exception {
		String msg = this.checkUacStaffData();
		if (null != msg) {
			Messagebox.show(msg);
			return;
		}
		// 获取登录用户
		String currentName = "";
		if (StrUtil.isNullOrEmpty(PlatformUtil.getCurrentUser())) {
			ZkUtil.showError("当前登录用户已经失效，请重新登录系统", "错误提示");
			return;
		} else {
			currentName = PlatformUtil.getCurrentUser().getScreenName();
		}
		// if ("add".equals(opType)) {
		// uecPsnjob = UecPsnjob.newInstance();
		// PubUtil.fillPoFromBean(bean, uecPsnjob);
		// uecPsnjob.setStaffId(qryUecOutStaffInfo.getOutStaffId());
		// uecPsnjob.setNmStaffType(BaseUnitConstants.NM_OUT_STAFF_TYPE);
		// uecPsnjob.setPkPsndoc(qryUecOutStaffInfo.getPkPsnMsg());
		// // 将前台获取的Datel类型日期转为String
		// if (!StrUtil.isNullOrEmpty(bean.getBegindate().getValue())) {
		// uecPsnjob.setBegindate(DateUtil.dateToStr(bean.getBegindate().getValue()));
		// }
		// if (!StrUtil.isNullOrEmpty(bean.getEnddate().getValue())) {
		// uecPsnjob.setEnddate(DateUtil.dateToStr(bean.getEnddate().getValue()));
		// }
		// if (!StrUtil.isNullOrEmpty(bean.getJobglbdef8().getValue())) {
		// uecPsnjob.setJobglbdef8(DateUtil.dateToStr(bean.getJobglbdef8().getValue()));
		// }
		// if (!StrUtil.isNullOrEmpty(bean.getJobglbdef14().getValue())) {
		// uecPsnjob.setJobglbdef14(DateUtil.dateToStr(bean.getJobglbdef14().getValue()));
		// }
		// if (!StrUtil.isNullOrEmpty(bean.getJobglbdef15().getValue())) {
		// uecPsnjob.setJobglbdef15(DateUtil.dateToStr(bean.getJobglbdef15().getValue()));
		// }
		// if (!StrUtil.isNullOrEmpty(bean.getJobglbdef16().getValue())) {
		// uecPsnjob.setJobglbdef16(DateUtil.dateToStr(bean.getJobglbdef16().getValue()));
		// }
		// // 获取组织、部门
		// if (null != findUecOrgDept) {
		// // 如果新增的任职信息中的组织与老的qryUecOutStaffInfo中的组织不一样，那么需要更新
		// if
		// (!qryUecOutStaffInfo.getPkHrorg().equals(findUecOrgDept.getPkOrg()))
		// {
		// outStaffInfoUpdateFlag = true;
		// // 更新人员基本信息中的组织
		// qryUecOutStaffInfo.setPkHrorg(findUecOrgDept.getPkOrg());
		// qryUecOutStaffInfo.setModifier(currentName);
		// qryUecOutStaffInfo.setModifiedTime(DateUtil.getCurrenDate());
		// } else {
		// outStaffInfoUpdateFlag = false;
		// }
		// // 组织
		// uecPsnjob.setPkOrg(findUecOrgDept.getPkOrg());
		// uecPsnjob.setPkHrorg(findUecOrgDept.getPkOrg());
		// // 部门
		// uecPsnjob.setPkDept(findUecOrgDept.getPkDept());
		// }
		// /**
		// * 一二三级基准岗位
		// */
		// // 三级基准岗
		// if (basePostVo != null) {
		// uecPsnjob.setJobglbdef24(basePostVo.getCode());
		// // 二级基准岗
		// uecPsnjob.setJobglbdef23(basePostVoB.getCode());
		// // 一级基准岗
		// uecPsnjob.setJobglbdef22(basePostVoA.getCode());
		// }
		// // 获取领导职务
		// String jobGlbdef25 = (String)
		// bean.getJobglbdef25().getSelectedItem().getValue();
		// uecPsnjob.setJobglbdef25(jobGlbdef25);
		// // 负责部门
		// /**
		// * 如果领导职务为：部门第一负责人或者部门其他负责人，负责部门取部门
		// */
		// if ("1001AA100000001ZIHCY".equals(jobGlbdef25) ||
		// "1001AA100000001ZIHCZ".equals(jobGlbdef25)) {
		// uecPsnjob.setJobglbdef26(findUecOrgDept.getPkDept());
		// }
		// // 获取岗位
		// if (null != uecPost) {
		// uecPsnjob.setPkPost(uecPost.getPkPost());
		// uecPsnjob.setOutJobName(uecPostManager.getUecPostNameByPkPost(uecPsnjob.getPkPost()));
		// }
		// // 创建人
		// uecPsnjob.setCreator(currentName);
		// // 创建时间
		// uecPsnjob.setCreationtime(DateUtil.getCurrenDate());
		//
		// // 如果组织有变动，外包人员信息需要同步
		// if (outStaffInfoUpdateFlag) {
		// qryUecOutStaffInfo.updateOnly();
		// }
		// // 新增入库
		// uecPsnjob.addOnly();
		// Events.postEvent("onOK", this.self, uecPsnjob);
		// this.onCancel();
		// Messagebox.show("新增成功！");
		// }
		if ("edit".equals(opType)) {
			PubUtil.fillPoFromBean(bean, qryUecPsnjob);
			// 一级基准岗位
			qryUecPsnjob.setJobglbdef22(temporaryUecPsnjob.getJobglbdef22());
			// 二级基准岗位
			qryUecPsnjob.setJobglbdef23(temporaryUecPsnjob.getJobglbdef23());
			// 三级基准岗位
			qryUecPsnjob.setJobglbdef24(temporaryUecPsnjob.getJobglbdef24());
			// 领导职务
			qryUecPsnjob.setJobglbdef25(temporaryUecPsnjob.getJobglbdef25());
			// 负责部门
			//qryUecPsnjob.setJobglbdef26(temporaryUecPsnjob.getJobglbdef26());
			
			//人员类别（新）
			if(StrUtil.isNullOrEmpty(bean.getUecPsncl())) {
				ZkUtil.showError("请选择人员类别！", "错误提示");
				return;
			}
			if(bean.getUecPsncl().getUecBdPsncls()!=null) {
			String uecPsncl=bean.getUecPsncl().getUecBdPsncls().get(0).getName();
			String uecPsnclOld=temporaryUecPsnjob.getPkPsnclName();
				if(!uecPsncl.equals(uecPsnclOld)) {
					if(!StrUtil.isNullOrEmpty(uecPsncl)) {
				       qryUecPsnjob.setPkPsncl(bean.getUecPsncl().getUecBdPsncls().get(0).getPkPsncl());
					}
				}else {
					qryUecPsnjob.setPkPsncl(temporaryUecPsnjob.getPkPsncl());
				}
			}
			//岗位层级（新）
			if(bean.getNewPostLevel().getUecBdDefdocs()!=null) {
				String uecPsncl=bean.getNewPostLevel().getUecBdDefdocs().get(0).getName();
				String uecPsnclOld=temporaryUecPsnjob.getJobglbdef2Name();
				if(!uecPsncl.equals(uecPsnclOld)) {
					if(!StrUtil.isNullOrEmpty(uecPsncl)) {
						qryUecPsnjob.setJobglbdef2(bean.getNewPostLevel().getUecBdDefdocs().get(0).getPkDefdoc());
					}
				}else {
					qryUecPsnjob.setJobglbdef2(temporaryUecPsnjob.getJobglbdef2());
				}
			}else {
				qryUecPsnjob.setJobglbdef2(temporaryUecPsnjob.getJobglbdef2());
			}
			//岗位等级（新）
			if(bean.getPostGrade().getUecBdDefdocs()!=null) {
				String uecPsncl=bean.getPostGrade().getUecBdDefdocs().get(0).getName();
				String uecPsnclOld=temporaryUecPsnjob.getJobglbdef3Name();
				if(!uecPsncl.equals(uecPsnclOld)) {
					if(!StrUtil.isNullOrEmpty(uecPsncl)) {
						qryUecPsnjob.setJobglbdef3(bean.getPostGrade().getUecBdDefdocs().get(0).getPkDefdoc());
					}
				}else {
					qryUecPsnjob.setJobglbdef3(temporaryUecPsnjob.getJobglbdef3());
				}
			}else {
				qryUecPsnjob.setJobglbdef3(temporaryUecPsnjob.getJobglbdef3());
				
			}
			// 将页面Date类型的日期改为String类型
			if (!StrUtil.isNullOrEmpty(bean.getBegindate().getValue())) {
				qryUecPsnjob.setBegindate(DateUtil.dateToStr(bean
						.getBegindate().getValue()));
			}
			if (!StrUtil.isNullOrEmpty(bean.getEnddate().getValue())) {
				qryUecPsnjob.setEnddate(DateUtil.dateToStr(bean.getEnddate()
						.getValue()));
			}
			if (!StrUtil.isNullOrEmpty(bean.getJobglbdef8().getValue())) {
				qryUecPsnjob.setJobglbdef8(DateUtil.dateToStr(bean
						.getJobglbdef8().getValue()));
			}
			if (!StrUtil.isNullOrEmpty(bean.getJobglbdef14().getValue())) {
				qryUecPsnjob.setJobglbdef14(DateUtil.dateToStr(bean
						.getJobglbdef14().getValue()));
			}
			if (!StrUtil.isNullOrEmpty(bean.getJobglbdef15().getValue())) {
				qryUecPsnjob.setJobglbdef15(DateUtil.dateToStr(bean
						.getJobglbdef15().getValue()));
			}
			if (!StrUtil.isNullOrEmpty(bean.getJobglbdef16().getValue())) {
				qryUecPsnjob.setJobglbdef16(DateUtil.dateToStr(bean
						.getJobglbdef16().getValue()));
			}
			if (null != findUecOrgDept) {
				// 如果新增的任职信息中的组织与老的qryUecOutStaffInfo中的组织不一样，那么需要更新
				if (!qryUecOutStaffInfo.getPkHrorg().equals(
						findUecOrgDept.getPkOrg())) {
					outStaffInfoUpdateFlag = true;
					// 更新人员基本信息中的组织
					uecOutStaffInfo.setPkHrorg(findUecOrgDept.getPkOrg());
					uecOutStaffInfo.setModifier(currentName);
					uecOutStaffInfo.setModifiedTime(DateUtil.getCurrenDate());
				} else {
					outStaffInfoUpdateFlag = false;
				}
				// 组织
				qryUecPsnjob.setPkOrg(findUecOrgDept.getPkOrg());
				qryUecPsnjob.setPkHrorg(findUecOrgDept.getPkOrg());
				// 部门
				qryUecPsnjob.setPkDept(findUecOrgDept.getPkDept());
			}
			if (null != uecPost) {
				qryUecPsnjob.setPkPost(qryUecPsnjob.getPkPost());
				qryUecPsnjob.setOutJobName(uecPostManager
						.getUecPostNameByPkPost(qryUecPsnjob.getPkPost()));
			}
			qryUecPsnjob.setModifier(currentName);
			qryUecPsnjob.setModifiedtime(DateUtil.getCurrenDate());

			// 外包人员更新标志
			if (outStaffInfoUpdateFlag) {
				qryUecOutStaffInfo.updateOnly();
			}
			// 更新入库
			qryUecPsnjob.updateOnly();
			Events.postEvent("onOK", this.self, qryUecPsnjob);
			this.onCancel();
			Messagebox.show("更新成功！");

			/**
			 * 启动流程
			 */
			// String procDefId =
			// "outStaffPsnjobEdit:1:ec37e0000607445d80e0b5854d7362f2";
			// String formTheme = "盟市外包人员兼职审批流程";
			// String urgent = "1";
			// String formContent = "兼职人:wangyiren";
			// String atiActCategoryId = "21";
			// String startFlowJson = "{" +
			// "formTheme: '盟市人员信息修改流程',"+
			// " formContent: '信息修改人:wangyiren',"+
			// " procDefId: 'outStaffEdit:1:11151202bbc143739de6f5eefdaace17',"+
			// " urgent: '1',"+
			// " atiActCategoryId: '21',"+
			// " procDefKey: '" + ApprovalUtil.OUT_STAFF_PSNJOB_EDIT + "',"+
			// " primaryId: " + uecPsnjob.getId() +
			// "}" ;
			// ApprovalUtil.startApproval(startFlowJson);

		}
	}

	/**
	 * 取消
	 */
	public void onCancel() {
		// 关闭窗口
		this.bean.getUecOutStaffPsnjobEditWindow().onClose();
	}

	/**
	 * 检测填入的参数是否为空
	 */
	private String checkUacStaffData() {
		if (StrUtil.isNullOrEmpty(bean.getOutStaffPkDept().getValue())) {
			return "填选择部门";
		}
		return null;
	}

	/**
	 * 将String类型的时间转换成Date类型
	 * 
	 * @throws ParseException
	 */
	public void stringTransToDate() throws ParseException {
		// 时间类型转换：String --> Date
		// 开始日期
		if (null != qryUecPsnjob.getBegindate()) {
			bean.getBegindate().setValue(
					DateUtil.patternStrToDate(qryUecPsnjob.getBegindate()));
		}
		// 结束日期
		if (null != qryUecPsnjob.getEnddate()) {
			bean.getEnddate().setValue(
					DateUtil.patternStrToDate(qryUecPsnjob.getEnddate()));
		}
		// 任现岗级时间
		if (null != qryUecPsnjob.getJobglbdef8()) {
			bean.getJobglbdef8().setValue(
					DateUtil.patternStrToDate(qryUecPsnjob.getJobglbdef8()));
		}
		// 现职时间
		if (null != qryUecPsnjob.getJobglbdef14()) {
			bean.getJobglbdef14().setValue(
					DateUtil.patternStrToDate(qryUecPsnjob.getJobglbdef14()));
		}
		if (null != qryUecPsnjob.getJobglbdef15()) {
			bean.getJobglbdef15().setValue(
					DateUtil.patternStrToDate(qryUecPsnjob.getJobglbdef15()));
		}
		if (null != qryUecPsnjob.getJobglbdef16()) {
			bean.getJobglbdef16().setValue(
					DateUtil.patternStrToDate(qryUecPsnjob.getJobglbdef16()));
		}
	}

	/**
	 * 绑定combobox
	 */
	private void bindCombobox() {

		// 任职方式
		ListboxUtils.rendererForEdit(bean.getJobmode(),
				NodeVoUtil.getDictionaries(UecConstants.WAY_OF_TENURE));
		// 免职方式
		ListboxUtils.rendererForEdit(bean.getDeposemode(),
				NodeVoUtil.getDictionaries(UecConstants.WAY_OF_DISMISSAL));
		// 领导职务
		ListboxUtils.rendererForEdit(bean.getJobglbdef25(),
				NodeVoUtil.getDictionaries(UecConstants.LEADING_POSITION));
		// 进入本单位来源jobglbdef10-
		ListboxUtils.rendererForEdit(bean.getJobglbdef10(),
				NodeVoUtil.getDictionaries(UecConstants.ASSCESS_SOURCE_UTIL));
		// 岗位层级--JOBGLBDEF2
		/*ListboxUtils.rendererForEdit(bean.getJobglbdef2(),
				NodeVoUtil.getDictionaries(UecConstants.POST_HIERARCHY));*/
		// 岗位层级--JOBGLBDEF2
		ListboxUtils.rendererForEdit(bean.getJobglbdef2(),
				NodeVoUtil.getDictionaries(UecConstants.POST_HIERARCHY_NEW));		
		// 岗位等级--Jobglbdef3
		ListboxUtils.rendererForEdit(bean.getJobglbdef3(),
				NodeVoUtil.getDictionaries(UecConstants.POST_LEVEL));
		// 岗位工资档次 --JOBGLBDEF9-
		ListboxUtils.rendererForEdit(bean.getJobglbdef9(),
				NodeVoUtil.getDictionaries(UecConstants.WAGES_LEVEL));
		// 岗位序列--pkPostseries
		List<NodeVo> nodeVoPkPostseriesList = new ArrayList<NodeVo>();
		String[][] pkPostseries = { { "1001A1100000000006R2", "管理序列" },
				{ "1001A1100000000006R3", "专业序列" } };
		for (int i = 0; i < pkPostseries.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(pkPostseries[i][j]);
				nodeVo.setName(pkPostseries[i][j + 1]);
			}
			nodeVoPkPostseriesList.add(nodeVo);
		}
		// 人员类别
		// 人员类别--PSNCL_PK_ORG
		ListboxUtils.rendererForEdit(bean.getPkPsncl(),
				NodeVoUtil.getDictionariesPsncl(UecConstants.PSNCL_PK_ORG));

		// 异动原因
		ListboxUtils.rendererForEdit(bean.getTrnsreason(),
				NodeVoUtil.getDictionaries(UecConstants.CHANGR_REASON));
		// 人员状态jobglbdef1-
		ListboxUtils.rendererForEdit(bean.getJobglbdef1(),
				NodeVoUtil.getDictionaries(UecConstants.PERSONAL_STATUS));
		// 任职类型psnjobtype-
		ListboxUtils.rendererForEdit(bean.getPkJobType(),
				NodeVoUtil.getDictionaries(UecConstants.PSNJOBTYPE));
		// 异动类型--trnstype
		List<NodeVo> nodeVotrnstypeList = new ArrayList<NodeVo>();
		String[][] trnstype = { { "1001A110000000000R1U", "上岗" },
				{ "1001A110000000000R1V", "其他" },
				{ "1001A110000000000R1X", "员工终止合同" },
				{ "1001A110000000000R1Y", "死亡（在职）" },
				{ "1001A110000000000R1Z", "调出集团（不含成建制）" },
				{ "1001A110000000000R21", "派遣制员工离职" },
				{ "1001A1100000000MDKS4", "其他-新岗位体系上线" },
				{ "1002Z710000000008938", "聘用" },
				{ "1002Z710000000008GSF", "转正" },
				{ "1002Z710000000008GSN", "单位内调配" },
				{ "1002Z710000000008GSO", "跨单位调配" },
				{ "1002Z710000000008GSV", "离退休" },
				{ "1002Z710000000008GSW", "退职" },
				{ "1002Z710000000008GSZ", "员工解除合同" },
				{ "1002Z710000000008PAW", "企业解除合同" },
				{ "1002Z710000000011BD5", "跨单位调配" } };
		for (int i = 0; i < trnstype.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(trnstype[i][j]);
				nodeVo.setName(trnstype[i][j + 1]);
			}
			nodeVotrnstypeList.add(nodeVo);
		}
		ListboxUtils.rendererForEdit(bean.getTrnstype(), nodeVotrnstypeList);

		// 是否试用trialFlag-
		List<NodeVo> nodeVoList = new ArrayList<NodeVo>();
		String[][] trialFlag = { { "Y", "是" }, { "N", "否" } };
		for (int i = 0; i < trialFlag.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(trialFlag[i][j]);
				nodeVo.setName(trialFlag[i][j + 1]);
			}
			nodeVoList.add(nodeVo);
		}
		ListboxUtils.rendererForEdit(bean.getTrialFlag(), nodeVoList);
		// 人员状态-
		ListboxUtils.rendererForEdit(bean.getGlbdef1(), nodeVoList);
		// 是否主职
		ListboxUtils.rendererForEdit(bean.getIsmainjob(), nodeVoList);
		// 是否在岗-
		ListboxUtils.rendererForEdit(bean.getPoststat(), nodeVoList);
		// 是否结束-
		ListboxUtils.rendererForEdit(bean.getEndflag(), nodeVoList);
		// 试用trialType-
		List<NodeVo> nodeVoTrialTypeList = new ArrayList<NodeVo>();
		String[][] trialType = { { "1", "入职试用" }, { "2", "转岗试用" } };
		for (int i = 0; i < trialType.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(trialType[i][j]);
				nodeVo.setName(trialType[i][j + 1]);
			}
			nodeVoTrialTypeList.add(nodeVo);
		}
		ListboxUtils.rendererForEdit(bean.getTrialType(), nodeVoTrialTypeList);

		// 人员类型psntype-
		List<NodeVo> nodeVoPsntypeList = new ArrayList<NodeVo>();
		String[][] psntype = { { "0", "新进" }, { "1", "变更" }, { "2", "退出" } };
		for (int i = 0; i < psntype.length; i++) {
			NodeVo nodeVo = new NodeVo();
			for (int j = 0; j < 1; j++) {
				nodeVo.setId(psntype[i][j]);
				nodeVo.setName(psntype[i][j + 1]);
			}
			nodeVoPsntypeList.add(nodeVo);
		}
		ListboxUtils.rendererForEdit(bean.getPsntype(), nodeVoPsntypeList);
	}

}
